package cn.wolfcode.luowowo.exception;

import cn.wolfcode.luowowo.util.JsonResult;
import com.alibaba.fastjson.JSON;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@ControllerAdvice
public class CommonExceptionHandler {

    @ExceptionHandler(LogicException.class)
    @ResponseBody
    public Object logicException(Exception e, HttpServletResponse resp) {
        e.printStackTrace();
        return new JsonResult(JsonResult.CODE_ERROR_PARAM,e.getMessage(),null,false);
    }

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Object runTimeExp(Exception e, HttpServletResponse resp) {
        e.printStackTrace();
        return JsonResult.defaultError();
    }
}
